package com.zzx.bms.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zzx.bms.domain.User;
import com.zzx.bms.service.IUserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.HttpSessionRequiredException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * Created by SamZhao on 2016/12/5.
 */
@Controller
@RequestMapping("/login")
public class LoginController {

    private static Logger logger = Logger.getLogger(LoginController.class);

    @Autowired
    private IUserService userService;

    @RequestMapping(value = "/index")
    public String loginIndex(Model model){
        logger.info(new Date());
        return "login/login";
    }

    @RequestMapping(value = "/loginCheck")
    public  @ResponseBody String checkLogin(String username, String userpassword, Model model, HttpSession session){
        String success = "0";
        User user = userService.findUser(username,userpassword);
        if(user!=null)
            session.setAttribute("user",user);
        else
            success = "1";
        return success;
    }

}
